# -*- coding: utf-8 -*-

# === 送信済みメール一覧の管理用コントローラ
class Portal::MessageOutboxController < ApplicationController
  # === 送信済みメール一覧の表示
  def index
    paginate_opts = {:per_page => 5,
                     :order => "created_at DESC",
                     :page => params[:page]}
    @messages = current_user.my_messages.paginate(paginate_opts)
  end

  # === 個別の送信済みメールの詳細表示
  def show
    @message = Message.find(params[:id])
    if request.mobile?
      messages = current_user.my_messages
      cm_index = messages.count(:conditions => ["created_at <= ?", @message.created_at]) - 1
      if cm_index <= 0
        tmp, @next_message = messages.offset(cm_index).limit(2)
        @prev_message = nil
      else
        @prev_message, tmp, @next_message = messages.offset(cm_index - 1).limit(3)
      end
    end
  end
end
